import time as t
import calendar
from datetime import date, time, datetime

def own_datetime():
    #1752046558.5604808 1970 年 1 月 1 日开始的秒
    print(t.time())
    #2025-07-09 16:28:51.673896
    print(datetime.now())
    #16:28:51.673896
    print(datetime.now().time())
    #1752049731.673896
    print(datetime.now().timestamp())

    #以元祖显示日期时间
    #time.struct_time(tm_year=2025, tm_mon=7, tm_mday=9, tm_hour=15, tm_min=41, tm_sec=50, tm_wday=2, tm_yday=190, tm_isdst=0)
    print(t.localtime())
    #print(time.localtime(time.time()))

    #获取格式化的时间
    #Wed Jul  9 15:44:42 2025
    print(t.asctime())
    #print(time.asctime(time.localtime()))

    #推荐使用
    print(datetime.now())
    pass


def own_format():

    #格式化日期 datetime → str
    print(t.strftime("%Y-%m-%d %H:%M:%S", t.localtime()))

    # 格式化成Sat Mar 28 22:24:24 2016形式
    print(t.strftime("%a %b %d %H:%M:%S %Y", t.localtime()))

    localtime=t.strptime("1925-04-28 22:22:22","%Y-%m-%d %H:%M:%S")
    # parse字符串 y是 两个长度的年
    print(t.strftime("%y-%m-%d %H:%M:%S",localtime))

    pass

def own_advanced():
    #是否是闰年
    print(calendar.isleap(datetime.now().year))
    #获取周一开始的 今日 周次
    year,week,day=datetime.now().isocalendar()
    print(year,week,day)

    #指定年月日 时分秒
    d=date(2023,12,31)
    t=time(23,12,31)
    print(datetime.combine(d,t))

    #
    cal=calendar.Calendar(firstweekday=5)
    #打印每一天 前四天算作2024年的最后四天  按0显示
    # for itermonthday in cal.itermonthdays(2025, 1):
    #     print(itermonthday)

    #按周  返回列表  元素为每周的天数
    # [0, 0, 0, 0, 1, 2, 3]
    # [4, 5, 6, 7, 8, 9, 10]
    # [11, 12, 13, 14, 15, 16, 17]
    # [18, 19, 20, 21, 22, 23, 24]
    # [25, 26, 27, 28, 29, 30, 31]
    for monthdayscalendar in cal.monthdayscalendar(2025, 1):
        print(monthdayscalendar)

    pass

if __name__ == '__main__':
    #own_datetime()
    #own_format()
    own_advanced()
    pass